/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ucm;

import sql.Insert;
import sql.Update;

/**
 *
 * @author Donghui
 */
public class NewBookBorrower {

    private static NewBookBorrower local;
    private String msg;
    private String data[];
    private String sql;

    public static NewBookBorrower getInstance(String tp)
    {
        if(local==null)
        {
            local=new NewBookBorrower();
            local.msg=tp;
        }
        else
        {
            local.msg=tp;
        }
        return local;
    }

    public String run()
    {
        data=msg.split(";");
        sql="INSERT INTO bookborrower(bid, roll_id, name, title, borrowed_date, return_date) " +
                "VALUES('"+ data[0] +"', '"+ data[1] +"','"+ data[2] +"','"+ data[3] +"','"+ data[4] +"','"+ data[5] +"')";
        String tp=Insert.getInstance().insertValue(sql)+";10";
        sql="UPDATE book SET borrowed='N' WHERE bid='"+data[0]+"'";
        Update.getInstance().updateValue(sql);
        return tp;
    }

}
